﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace RexToy.UI.WinForm.Controls
{
    static class ToolStripItemExtension
    {
        public static string GetNameWithoutPrefix(this ToolStripItem item)
        {
            int idx;
            for (idx = 0; idx < item.Name.Length; idx++)
            {
                if (char.IsLower(item.Name[idx]))
                    continue;
                else
                    break;
            }
            return item.Name.Substring(idx);
        }

        public static string GetBindProperty(this ToolStripItem item, string propertyName)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                if (string.IsNullOrEmpty(item.Name))
                    return string.Empty;
                else
                    return item.GetNameWithoutPrefix();
            }
            else
                return propertyName;
        }
    }
}
